package com.LeetCode;
/*
* 给出一个 32 位的有符号整数，你需要将这个整数中每位上的数字进行反转。
* */
public class _7正数反转
{
    public static void main(String[] args)
    {
        System.out.println(reverse(-1234567890));
    }
    public static int reverse(int x) {
        int rev = 0;
        int max = Integer.MAX_VALUE;
        int min = Integer.MIN_VALUE;
        while (x != 0) {
            int temp = x % 10;
            x /= 10;
            if (rev > max/10 || (rev == max / 10 && temp > 7)) return 0;
            if (rev < min/10 || (rev == min / 10 && temp < -8)) return 0;
            rev = rev * 10 + temp;
        }
        return rev;
    }
}
